var rootview = ui("$");
var app = sm("do_App");
var page = sm("do_Page");
var nf = sm("do_Notification");
var global = require("helper/global");
var bizzType = require("helper/bizzType");
var pubUrl = require("url/pub");
var sendALayout = ui("sendALayout");
var sendBtn = ui("sendBtn");
var cancelBtn = ui("cancelBtn");
var textContent = ui("textContent");
var http = require("helper/http");
var communityUtil = require("helper/community");

var bizzId;
var bizzType;
var beCommentedId = null; //被回复的评论ID
var beCommentedName = null;//被回复的用户名
//文字改变
textContent.on("textChanged", function(data, e) {

});

//发送文字消息
sendBtn.on("touch","",3000,function(data, e) { 
	page.hideKeyboard();
	if(textContent.text==""){
		nf.toast("请输入内容!");
		return;
	}
	var addParams = {
        bizzId:bizzId,
        bizzType:bizzType,
		content:textContent.text,
		beCommentedId:beCommentedId,
		communityId:communityUtil.communityVisitId()
	};
	http.post(pubUrl.url.comment.doAdd,addParams,function(data){
		page.fire("sendTextMsg",data);
		textContent.text = "";
		page.fire("bottomHide");
	});
	
});

//取消发送
cancelBtn.on("touch", function(data, e) { 
	page.hideKeyboard();
	textContent.text = "";
	beCommentedId = null;
	beCommentedName = null;
	textContent.hint = "评论";
	page.fire("bottomHide");
});

//回复非当前用户时，触发显示评论输入框
page.on("commentOther",function(data) {
	if(data.beCommentedId!==undefined&&data.beCommentedId){
		beCommentedId = data.beCommentedId;
		beCommentedName = data.beCommentedName;
		textContent.hint = "回复"+beCommentedName;
	}
	bizzId = data.bizzId;
	bizzType = data.bizzType;
	global.setTimeout(function(){
		textContent.setFocus(true);
	},100,"timerComment");
});

